package com.ambulance.project.biz.controller.uni;


import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.project.biz.entity.ReceiveInterfaceLog;
import com.ambulance.project.biz.enums.MyModel;
import com.ambulance.project.biz.service.ReceiveInterfaceLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * <p>
 * 人员信息 前端控制器
 * </p>
 *
 * @author zr
 * @since 2020-04-21
 */

@RestController
@RequestMapping(value = "/uni/v1/post")

public class UniController {


    private static Logger logger = LoggerFactory.getLogger(UniController.class);

    @Autowired
    private ReceiveInterfaceLogService receiveInterfaceLogService;

    /**
     * 接收联通推送报文
     *
     * @param body
     * @param token
     * @return
     */
    @RequestMapping(value = "/ecg")
    public Object info(@RequestHeader(value = "token", required = false) String token,
                       HttpServletRequest request,
                       @RequestBody Object body) {
        logger.info("token {},obj {}", token, body);
        //do 接收推送报文并写入数据库
        String uri = request.getRequestURI();
        ReceiveInterfaceLog receiveInterfaceLog = new ReceiveInterfaceLog();
        receiveInterfaceLog.setReqTime(LocalDateTime.now());
        receiveInterfaceLog.setModelName(MyModel.ECG.name());
        receiveInterfaceLog.setRequest(body.toString());
        receiveInterfaceLog.setReqUrl(uri);
        AjaxResult success = AjaxResult.success();
        receiveInterfaceLog.setResponse(success.toString());
        receiveInterfaceLog.setRespTime(LocalDateTime.now());
        receiveInterfaceLogService.save(receiveInterfaceLog);

        return success;
    }


}
